﻿Imports BE.BE

Namespace DAL
    Public Class DAL_Cliente
        Shared Sub altaCliente(pCliente As Cliente_BE)

            Try
                pCliente.IdCliente = Helper_DAL.ObtenerProximoId("cliente")
            Catch ex As Exception
                Throw ex
            End Try
            
            Dim strcomm As String = "insert into cliente (id_cliente, id_persona, poliza, estado) values " & _
                "(" & pCliente.IdCliente & "," & pCliente.Id & "," & pCliente.Poliza & ",'" & pCliente.Estado & "')"

            Try
                Helper_DAL.ExecuteNonQuery(strcomm)
            Catch ex As Exception
                Throw ex
            End Try


        End Sub

        Shared Sub bajaCliente(pCliente As Cliente_BE)

        End Sub

        Shared Sub modificarCliente(pCliente As Cliente_BE)

        End Sub

        Shared Function listarClientes() As List(Of Cliente_BE)
            Dim mlista As New List(Of Cliente_BE)
            Dim mDS As New DataSet
            Dim strcomm As String = "select c.id_cliente, c.id_persona, c.poliza, c.estado, p.nombre, p.apellido, p.dni, p.fecha_nacimiento " & _
                " from cliente c inner join persona p on c.id_persona = p.id_persona"


            Try
                mDS = Helper_DAL.ExecuteDataset(strcomm)

                If mDS.Tables(0).Rows.Count > 0 Then

                    For Each dr As DataRow In mDS.Tables(0).Rows
                        Dim mCli As New Cliente_BE

                        mCli.IdCliente = dr.Item(0)
                        mCli.Id = dr.Item(1)
                        mCli.Poliza = dr.Item(2)
                        mCli.Estado = dr.Item(3)
                        mCli.Nombre = dr.Item(4).ToString
                        mCli.Apellido = dr.Item(5).ToString
                        mCli.DNI = dr.Item(6)
                        mCli.FechaNacimiento = dr.Item(7).ToString

                        mlista.Add(mCli)
                    Next



                End If

                Return mlista

            Catch ex As Exception
                Throw ex
            End Try


        End Function





    End Class

End Namespace
